---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: controller
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "controller")) | nindent 2 }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: d8:metallb:controller
  {{- include "helm_lib_module_labels" (list . (dict "app" "metallb")) | nindent 2 }}
rules:
  - apiGroups:
      - ""
    resources:
      - services
      - namespaces
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - services/status
    verbs:
      - update
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      - create
      - patch
  - apiGroups:
      - policy
    resourceNames:
      - controller
    resources:
      - podsecuritypolicies
    verbs:
      - use
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: d8:metallb:controller
  {{- include "helm_lib_module_labels" (list . (dict "app" "controller")) | nindent 2 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: d8:metallb:controller
subjects:
  - kind: ServiceAccount
    name: controller
    namespace: d8-{{ .Chart.Name }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: controller
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "controller")) | nindent 2 }}
rules:
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - create
      - delete
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - ""
    resourceNames:
      - memberlist
    resources:
      - secrets
    verbs:
      - list
  - apiGroups:
      - apps
    resourceNames:
      - controller
    resources:
      - deployments
    verbs:
      - get
  - apiGroups:
      - metallb.io
    resources:
      - bgppeers
    verbs:
      - get
      - list
  - apiGroups:
      - metallb.io
    resources:
      - addresspools
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - metallb.io
    resources:
      - bfdprofiles
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - metallb.io
    resources:
      - ipaddresspools
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - metallb.io
    resources:
      - bgpadvertisements
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - metallb.io
    resources:
      - l2advertisements
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - metallb.io
    resources:
      - communities
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: controller
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "controller")) | nindent 2 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: controller
subjects:
  - kind: ServiceAccount
    name: controller
